<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north'" class="center">
        <div class="webmap">
            <p class="webmaptip">当前位置:</p>
            <a href="javascript:;" class="easyui-link" data-options="plain:true">用户管理</a>
            <p class="webmaptip">></p>
            <a href="javascript:;" class="easyui-link" data-options="plain:true">所有用户</a>
        </div>
        <div class="querybycon">
            <form id="query">
                <div class="queryinfo">
                    <div>手机号码<input type="text" name="telephone"></div>
                    <div>真实姓名<input type="text" name="name"></div>
                    <div class="db">注册时间<input name="beginTime" class="easyui-datetimebox">
                        -
                        <input name="endTime" class="easyui-datetimebox">
                    </div>
                    <div>注册来源<input class="easyui-combobox" name="plantFrom"
                                    data-options="url:'/dictionary/plantfrom?all=true'">
                    </div>
                    <div>是否实名<input class="easyui-combobox" name="authRealName" data-options="url:'/dictionary/wether'">
                    </div>
                    <div>是否绑卡<input class="easyui-combobox" name="authBindCard" data-options="url:'/dictionary/wether'">
                    </div>
                    <div>是否投资<input class="easyui-combobox" name="investState" data-options="url:'/dictionary/wether'">
                    </div>
                    <div>用户类型<input class="easyui-combobox" name="type" data-options="url:'/dictionary/userType'"></div>
                    <div class="query">
                        <a id="querybtn" href="javascript:;" class="easyui-linkbutton  "
                           data-options="iconCls:'fa fa-search'"></a>
                    </div>
                </div>
            </form>
        </div>
        <div class="querybtn">

            <a id="userInfo" href="javascript:;" class="easyui-linkbutton danger"
               data-options="iconCls:'fa fa-pencil'">查看</a>
            <a id="restPassword" href="javascript:;" class="easyui-linkbutton  warning"
               data-options="iconCls:'fa fa-plus'">重置密码</a>
            <a id="disableUser" href="javascript:;" class="easyui-linkbutton  warning"
               data-options="iconCls:'fa fa-plus'">禁用</a>
            <a id="enableUser" href="javascript:;" class="easyui-linkbutton  warning"
               data-options="iconCls:'fa fa-plus'">启用</a>
            <!-- <a id="add" href="javascript:;" class="easyui-linkbutton  warning"
                data-options="iconCls:'fa fa-plus'">添加</a>
             <a id="edit" href="javascript:;" class="easyui-linkbutton danger"
                data-options="iconCls:'fa fa-pencil'">编辑</a>
             <a id="del" href="javascript:;" class="easyui-linkbutton success"
                data-options="iconCls:'fa fa-remove'">删除</a>-->
            <div style="visibility: hidden;">aa</div>
        </div>
    </div>
    <div data-options="region:'center'" class="center">
        <table id="list"></table>
    </div>
</div>
<script type="text/javascript">
    var addUrl = "/system/useredit.html";
    var infoUrl = "/page/user/userinfo.html";
    var edit = "/dictionary/edit";
    var delUrl = '/user/del';
    var listUrl = "/user/list";
    var columns = [[{
        field: 'id',
        checkbox: true
    }, {
        field: 'telephone',
        title: '用户名',
    }, {
        field: 'type',
        title: '用户类型',
        formatter: function (value, row, index) {
            switch (value) {
                case 1:
                    return "投资人";
                case 2:
                    return "借款人";
                case 3:
                    return "混合人";
            }
        }
    }, {
        field: 'name',
        title: '姓名',
    }, {
        field: 'idCard',
        title: '身份证号',
        align: 'right'
    }, {
        field: 'telephone',
        title: '手机号',
    }, {
        field: 'email',
        title: '邮箱',
    }, {
        field: 'umpayId',
        title: '第三方账号',
    }, {
        field: 'plantFrom',
        title: '注册来源',
        formatter: function (value, row, index) {
            switch (value) {
                case "1":
                    return "pc";
                case "2":
                    return "app";
                case "3":
                    return "h5";
            }
        }
    }, {
        field: 'createdDate',
        title: '注册时间',
    }, {
        field: 'state',
        title: '状态',
        formatter: function (value, row, index) {
            return value == "1" ? "启用" : "禁用";
        }
    }]];
    list.init({url: listUrl, columns: columns});
</script>
<script>
    // 禁用用户
    $("#disableUser").click(function () {
        var rows = $('#list').datagrid('getChecked');
        if (rows.length != 1) {
            $.messager.alert('操作提示', '请选中一行数据', 'info');
            return false;
        }
        $.messager.confirm('提示', '您确定要禁用' + rows[0].telephone + '吗?', function (r) {
            if (r) {
                $.post("/user/disable", {id: rows[0].id}, function (data) {
                    $.messager.show({
                        title: '操作提示',
                        msg: data.message,
                        timeout: 2000,
                        showType: 'slide'
                    });
                    if (data.state == "SUCCESS") {
                        $('#list').datagrid('reload');
                        return true;
                    }
                }, "JSON")
            }
        });
    }); // 启用用户
    $("#enableUser").click(function () {
        var rows = $('#list').datagrid('getChecked');
        if (rows.length != 1) {
            $.messager.alert('操作提示', '请选中一行数据', 'info');
            return false;
        }
        $.messager.confirm('提示', '您确定要启用' + rows[0].telephone + '吗?', function (r) {
            if (r) {
                $.post("/user/enable", {id: rows[0].id}, function (data) {
                    $.messager.show({
                        title: '操作提示',
                        msg: data.message,
                        timeout: 2000,
                        showType: 'slide'
                    });
                    if (data.state == "SUCCESS") {
                        $('#list').datagrid('reload');
                        return true;
                    }
                }, "JSON")
            }
        });
    });


    // 重置密码
    $("#restPassword").click(function () {
        var rows = $('#list').datagrid('getChecked');
        if (rows.length != 1) {
            $.messager.alert('操作提示', '请选中一行数据', 'info');
            return false;
        }
        $.messager.confirm('提示', '初始密码为本人手机号的后6位,您确定要重置吗?', function (r) {
            if (r) {
                $.post("/user/rest/password", {id: rows[0].id}, function (data) {
                    $.messager.show({
                        title: '操作提示',
                        msg: data.message,
                        timeout: 2000,
                        showType: 'slide'
                    });
                    if (data.state == "SUCCESS") {
                        $('#list').datagrid('reload');
                        return true;
                    }
                }, "JSON")
            }
        });
    });
    //查看详情
    $("#userInfo").click(function () {
        var rows = $('#list').datagrid('getChecked');
        if (rows.length != 1) {
            $.messager.alert('操作提示', '请选中一行数据', 'info');
            return false;
        }
        $('#win').window({title: "用户详情"}).window('open').window('refresh', infoUrl);

        var rows = $('#list').datagrid('getChecked');
        $.get("/user/detail", {id: rows[0].id}, function (msg) {
            if (msg.state == "SUCCESS") {
                msg.data.state = (   msg.data.state == "1" ? "启用" : "禁用");

                //将属性对象的属性转属性.属性
                editJson(msg.data);

                $('#infoFrom').form('load', msg.data);
                $('#infoFrom').find("input").each(function () {
                    $(this).after($(this).val()).remove();
                })
            } else {
                $.messager.show({
                    title: '操作提示',
                    msg: msg.message,
                    timeout: 2000,
                    showType: 'slide'
                });
            }
        })
    });

    function editJson(obj) {
        for (var key in obj) {
            if (typeof obj[key] == "object") {
                for (var ckey in obj[key]) {
                    obj[key + "." + ckey] = obj[key][ckey];
                }
                delete obj[key]; //删除原有
            }
        }
        for (var key in obj) {
            if (typeof obj[key] == "object") {
                editJson(obj);
                break;
            }
        }
    }
</script>
